define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activtyc/teacher/index',
                    add_url: 'activtyc/teacher/add',
                    edit_url: 'activtyc/teacher/edit',
                    del_url: 'activtyc/teacher/del',
                    multi_url: 'activtyc/teacher/multi',
                    table: 'activity_teacher',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'address', title: __('Address')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'school', title: __('School')},
                        {field: 'nianji', title: __('Nianji'), searchList: {"1":__('Nianji 1'),"2":__('Nianji 2'),"3":__('Nianji 3'),"4":__('Nianji 4'),"5":__('Nianji 5'),"6":__('Nianji 6')}, formatter: Table.api.formatter.normal},
                        {field: 'xuezhi', title: __('Xuezhi')},
                        {field: 'get_grade', title: __('Get_grade'), searchList: {"1":__('Get_grade 1'),"2":__('Get_grade 2'),"3":__('Get_grade 3'),"4":__('Get_grade 4'),"5":__('Get_grade 5'),"6":__('Get_grade 6')}, formatter: Table.api.formatter.normal},
                        {field: 'subject', title: __('Subject'), searchList: {"1":__('Subject 1'),"2":__('Subject 2')}, formatter: Table.api.formatter.normal},
                        {field: 'banben', title: __('Banben'), searchList: {"1":__('Banben 1'),"2":__('Banben 2'),"3":__('Banben 3'),"4":__('Banben 4')}, formatter: Table.api.formatter.normal},
                        {field: 'intention', title: __('Intention')},
                        {field: 'thumb_img', title: __('Thumb_img'),formatter: Controller.api.formatter.avatar},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                avatar: function (value, row, index) {
                    return '<img width="45" height="45" src="'+value+'" class="img-circle">';
                },

            }
        }
    };
    return Controller;
});